package cn.lhf.myblog.http.requst.user;

import cn.lhf.myblog.context.Sex;
import cn.lhf.myblog.http.requst.Form;
import cn.lhf.myblog.db.entity.User;
import cn.lhf.myblog.service.UserService;

import static cn.lhf.myblog.utils.StringUtils.*;

public class RegisterForm implements Form<UserService, User> {
    private String username;
    private String password;
    private String password2;
    private String phone;
    private Sex sex;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setPassword2(String password2) {
        this.password2 = password2;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getPassword2() {
        return password2;
    }

    public String getPhone() {
        return phone;
    }

    public Sex getSex() {
        return sex;
    }

    @Override
    public User to() {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setPhone(phone);
        user.setSex(sex);
        return user;
    }

    @Override
    public boolean isForm() {
        return isNotEmpty(username) && isNotEmpty(password) && isNotEmpty(password2) && isNotEmpty(phone) && sex != null;
    }
}
